//二叉树的最近公共祖先
//class Solution {
//    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
//        if(root == null || q == null || p == null){
//            return null;
//        }
//        if(p == root || q == root){
//            return root;
//        }
//        TreeNode left = lowestCommonAncestor(root.left, q, p);
//        TreeNode right = lowestCommonAncestor(root.right, q, p);
//        if(left == q && right == p || left == p && right == q){
//            return root;
//        }else if(left == null){
//            return right;
//        }else{
//            return left;
//        }
//    }
//}

//从前序与中序遍历序列构造二叉树
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
//class Solution {
//    public int pi;
//    public TreeNode buildTree(int[] preorder, int[] inorder) {
//        int ir = inorder.length-1;
//        return buildTreeChild(preorder, inorder, 0, ir);
//    }
//
//    public TreeNode buildTreeChild(int[] preorder, int[] inorder,int il,int ir) {
//        if(il > ir){
//            return null;
//        }
//        int id = findId(preorder, inorder,il ,ir);
//        TreeNode root = new TreeNode(preorder[pi]);
//        pi++;
//        root.left = buildTreeChild(preorder, inorder, il, id-1);
//        root.right = buildTreeChild(preorder, inorder, id+1, ir);
//        return root;
//    }
//
//    public int findId(int[] preorder, int[] inorder, int il, int ir){
//        for(int i=il; i<=ir; i++){
//            if(inorder[i] == preorder[pi]){
//                return i;
//            }
//        }
//        return -1;
//    }
//}

//从中序与后序序列遍历二叉树

import java.util.PriorityQueue;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
//class Solution {
//    public int pi;
//    public TreeNode buildTree(int[] inorder, int[] postorder) {
//        pi = postorder.length-1;
//        int ir = inorder.length-1;
//        return buildTreeChild(postorder, inorder, 0, ir);
//    }
//    public TreeNode buildTreeChild(int[] postorder, int[] inorder,int il,int ir) {
//        if(il > ir){
//            return null;
//        }
//        int id = findId(postorder, inorder,il ,ir);
//        TreeNode root = new TreeNode(postorder[pi]);
//        pi--;
//        root.right = buildTreeChild(postorder, inorder, id+1, ir);
//        root.left = buildTreeChild(postorder, inorder, il, id-1);
//        return root;
//    }
//
//    public int findId(int[] postorder, int[] inorder, int il, int ir){
//        for(int i=il; i<=ir; i++){
//            if(inorder[i] == postorder[pi]){
//                return i;
//            }
//        }
//        return -1;
//
//    }
//}
import java.util.Comparator;

class IntCmp implements Comparator<Integer> {
    public int compare(Integer o1, Integer o2){
        return o2.compareTo(o1);
    }
}
class Solution{
    public static void main(String[] args) {
        PriorityQueue<Integer>q = new PriorityQueue<>(new IntCmp());
        q.offer(5);
        q.offer(9);
        q.offer(1);
        q.offer(2);
        q.offer(6);
        System.out.println(q.poll());
        System.out.println(q.poll());
        System.out.println(q.poll());
    }
}